﻿/**
 * 给定两个数组A和B
 * 两个人轮流走棋
 * 1. 先手选中一个i，得到Ai-1分
 * 2. 后手选中一个i，得到Bi-1分
 * 选过的不能再选，无论先手后手
 * 先手后手得分相减为目标，先手要求目标最大，后手要求目标最小
 * 问最后的得分
 * N只有6，直接暴力深搜
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

using llt = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int N;
vi A, B;
int Has = 0;

llt dfsA();

llt dfsB(){
    if(0 == Has) return 0;

    llt ans = -2E12;
    for(int i=0;i<N;++i){
        if(A[i] == 0 or B[i] == 0) continue;

        llt tmp = B[i] - 1;
        auto o = A[i];
        A[i] = 0; --Has;
        tmp -= dfsA();
        A[i] = o; ++Has;
        ans = max(ans, tmp);
    }
    return ans;
}

llt dfsA(){
    if(0 == Has) return 0;

    llt ans = -2E12;
    for(int i=0;i<N;++i){
        if(A[i] == 0 or B[i] == 0) continue;

        llt tmp = A[i] - 1;
        auto o = B[i];
        --Has;
        B[i] = 0;
        tmp -= dfsB();
        ++Has;
        B[i] = o;
        ans = max(ans, tmp);
    }
    return ans;
}

llt proc(){
    Has = N;
    llt ans = dfsA();
    return ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);
    int nofkase = 1;
    cin >> nofkase;
    while(nofkase--){
        cin >> N;
        A.assign(N, 0);
        B.assign(N, 0);
        for(auto & i : A) cin >> i;
        for(auto & i : B) cin >> i;
        cout << proc() << endl;
    }
    return 0;
}